//
//  WmcTeamSearchVM.swift
//  YPWatermarkCamera
//
//  Created by yupao_ios_macmini06 on 2022/9/27.
//

import Foundation

extension WmcTeamSearchVM {
    class CellModel: NSObject {
        // Lifecycle

        init(title: String,
             disTitle: String,
             disTitleColor: UIColor,
             actionType: ActionType)
        {
            self.title = title
            self.disTitle = disTitle
            self.disTitleColor = disTitleColor
            self.actionType = actionType
        }

        // Internal

        enum ActionType {
            case startDate
            case endDate
            case watermark
        }

        var title: String
        var disTitle: String
        var disTitleColor: UIColor
        var actionType: ActionType
    }
}

class WmcTeamSearchVM: WmcBaseVM {
    /// 数据列表
    let dataListRelay: BehaviorRelay<[[CellModel]]> = .init(value: [])

    /// 照片统计数据
    var photoStatistics: [WmcMediaTakePhotoDayModel] = []

    /// 所有水印
    var allWatermarks: [WmcSelectWatermarkModel] = []

    /// 选中的水印
    var selectedWatermarks: [WmcSelectWatermarkModel] = []

    var teamAblum: WmcMediaTeamAlbumModel?

    lazy var startDateStr: String = {
        let date = WmcDateManager.shared.networkDate.value ?? Date()
        let dateStr = date.yp.string("yyyy") + ".01.01"
        return dateStr
    }()

    lazy var startDateModel: CellModel = {
        let model = CellModel(title: "开始时间", disTitle: startDateStr, disTitleColor: .wmc_grayH2_323233, actionType: .startDate)
        return model
    }()

    lazy var endDateModel: CellModel = {
        let date = WmcDateManager.shared.networkDate.value ?? Date()
        let dateStr = date.yp.string("yyyy.MM.dd")
        let model = CellModel(title: "结束时间", disTitle: dateStr, disTitleColor: .wmc_grayH2_323233, actionType: .endDate)
        return model
    }()

    lazy var watermarkModel: CellModel = {
        let model = CellModel(title: "水印", disTitle: "选择水印", disTitleColor: .wmc_grayH8_8A8A99, actionType: .watermark)
        return model
    }()

    /// 加载数据
    func loadList(_: Date = WmcDateManager.shared.networkDate.value ?? .init()) {
        var list: [[CellModel]] = []
        let group_0: [CellModel] = [
            startDateModel,
            endDateModel,
            watermarkModel,
        ]
        list.append(group_0)

        dataListRelay.accept(list)
    }
}
